<?php
load_info_var($cf_controller);	   //加载smarty变量
load_file('board_class', LIB_PATH);
$main = new Board($db);
$id = isset($_POST['id']) ? intval($_POST['id']) : intval($_GET['id']);
$self = isset($_POST['self']) ? trim($_POST['self']) : trim($_GET['self']);
$return_page = $cf_pre_page ? $cf_pre_page : $cf_self_page;

switch ($cf_action) {
    case "index":	
	$smarty->mypage($cf_controller, $cf_action, 0);	
	$skey = isset($_POST['skey']) ? trim($_POST['skey']) : urldecode($_GET['skey']);
	$start = isset($_POST['start']) ? trim($_POST['start']) : urldecode($_GET['start']);
	$end = isset($_POST['end']) ? trim($_POST['end']) : urldecode($_GET['end']);	
	$where = '1';
	
	if ($skey) {
	    $where .= " and goods_name like '%" . $skey . "%'";
	}		
	if ($start && $end) {
            $where .= " AND DATE_FORMAT(board_create_time,'%Y-%m-%d')  BETWEEN '".$start."' AND '".$end."'";
    }	
	
	load_file('page_class', LIB_PATH);
	$MyPage = new Mypage($db);
	$field = 'data_board.*,goods_id,goods_name,goods_index_image,goods_board_least_number';
	$data_ary = $MyPage->from_sql($field, $main->get_table_name().' left join data_goods on board_gid = goods_id', $where, "board_id DESC", intval($_GET['cpage']), "20");
	$page = $MyPage->get_page($data, $cf_self_page . '?dpt=' . $cf_dpt . '&skey=' . $skey . '&cate=' . $cate . '&brand=' . $brand . '&start=' . $start.'&end='.$end);
	//echo $MyPage->get_sql();
	//dump($data_ary);
	//echo $MyPage->get_sql();
	//dump($data_ary);
	break;   
	case "detail":
	$smarty->mypage($cf_controller, $cf_action, 0);
	$row = $main->get_data_row($id);
	if (!$row)
	my_jump('沒有此信息');
	//获取商品的信息
	load_file('goods_class', LIB_PATH);
	$goods = new Goods($db);
	$goods_info = $goods->get_data_row($row['board_gid'],'goods_id,goods_name,goods_index_image,goods_board_least_number');
	$row['goods_info'] = $goods_info;
	
	
	
	//搭伙够的订单列表
	load_file('order_class', LIB_PATH);
	$order = new Order($db);
	load_file('page_class', LIB_PATH);
	$MyPage = new Mypage($db);
	$field = '*';
	$where = "order_boardid = '".$id."'";
	$opid =  intval($_GET['opid']);//拉王的id
	if($opid){
		$where .= " AND order_pid = '".$opid."'";
	}
	$data_ary = $MyPage->from_sql($field, $order->get_table_name(), $where, "order_id DESC", intval($_GET['cpage']), "3000");
	$page = $MyPage->get_page($data, $cf_self_page . '?dpt=' . $cf_dpt . '&skey=' . $skey . '&skey2=' . $skey2  .'&skey3=' . $skey3 .'&skey4=' . $skey4 .'&skey5=' . $skey5 .'&skey6=' . $skey6 .   '&self=' . $self);
	if($data_ary){
		foreach($data_ary as $k=>$v){
			$data_ary[$k]['order_detail'] = unserialize(stripslashes($v['order_detail']));	
		}
	}
	
	//拉王的数据
	$row['most_user'] = $main->get_most_user($id);	
	break;  
  
	
	default:
	my_jump('非法操作!');
	break;
}


$smarty->assign(array(
    'id' => $id,
    'row' => $row,
    'data_ary' => $data_ary,
    'page' => $page,
    'self' => $self,
    'skey' => $skey,  
    'brand' => $brand,
	'start' => $start,
	'end' => $end,	
));

$smarty->mydisplay();
?>